package com.iflytek.cbg.wxyy.gamebox.wechat.wechat.controller;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@RestController
@EnableAutoConfiguration
public class HelloController {

//    @RequestMapping(path = "/hello",method = RequestMethod.POST)
//    private String index(ServletRequest req, ServletResponse resp) {
//        return "Hello World!";
//    }

    @RequestMapping(path = "/hello",method = RequestMethod.GET)
    private void index(HttpServletRequest req, HttpServletResponse resp) {
//        return "Hello World!";
        PrintWriter print;
        // 微信加密签名
        String signature = req.getParameter("signature");
        // 时间戳
        String timestamp = req.getParameter("timestamp");
        // 随机数
        String nonce = req.getParameter("nonce");
        // 随机字符串
        String echostr = req.getParameter("echostr");
        // 通过检验signature对请求进行校验，若校验成功则原样返回echostr，表示接入成功，否则接入失败
        if (signature != null) {
            try {
                print = resp.getWriter();
                print.write(echostr);
                print.flush();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    @RequestMapping(path = "/msg",method = RequestMethod.POST)
    private void msg(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println("req = [" + req + "], resp = [" + resp + "]");
    }
}

//15_x8Rzeaa2LKiwbw4-oeYLcB_Mkh2E0nS3hzZdW6bs52LcgMAOTjAeStu7xTJSSavXIGoVMDN22UGbPEIRTpEJWwvr_pSMSj0_TXjfa_2HL7dpHCJ5P3ehl_Ae9CnzBiBb6I3S6eOyoJMwTsgrIJTdAFALMW

